package com.nuoniu.sibanyun.controller.production;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.inOut.VInOutRecordMain;
import com.nuoniu.sibanyun.entity.production.VProductionPickReturnMain;
import com.nuoniu.sibanyun.service.production.IVProductionPickReturnMainService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 生产领退补料单主表 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-01-15
 */
@RestController
@RequestMapping("/production/pickReturn")
@Api(value = "生产领退补料单管理", tags = "生产领退补料单管理")
public class VProductionPickReturnMainController extends BaseController {

    @Autowired
    private IVProductionPickReturnMainService productionPickReturnMainService;

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody VProductionPickReturnMain productionPickReturnMain) {
        if(productionPickReturnMain.getBusinessType() == null) {
            throw new NuoNiuException("业务类型不能为空");
        }
        productionPickReturnMainService.saveOrder(productionPickReturnMain);
        return HttpResult.ok();
    }


    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        productionPickReturnMainService.delete(id);
        return HttpResult.ok();
    }
    /**
     * 提交
     */
    @GetMapping("submit")
    @ApiOperation("单据提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:提交,-1:反提交")
    })
    public HttpResult submit(Long id, Integer status) {
        productionPickReturnMainService.submit(id, status);
        return HttpResult.ok();
    }
    @GetMapping("examine")
    @ApiOperation("单据审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:审核,1:已审")
    })
    public HttpResult examine(Long id, Integer status) {
        productionPickReturnMainService.examine(id, status);
        return HttpResult.ok();
    }

    @GetMapping("apply")
    @ApiOperation("提交申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 1:退单,2:提交申请")
    })
    public HttpResult apply(Long id, Integer status) {
        productionPickReturnMainService.apply(id,status);
        return HttpResult.ok();
    }
    /**
     * 获取单据编码
     * @author 小啊刚
     * @date 2021-01-18
     */
    @ApiOperation("获取单据编码")
    @GetMapping("getCode")
    public HttpResult getCode() {
        return HttpResult.ok(productionPickReturnMainService.getCode());
    }



    @ApiOperation("领料单 分单")
    @PostMapping("saveMyWarehouseInOut")
    public HttpResult saveMyWarehouseInOut(@RequestBody VInOutRecordMain vInOutRecordMain) {
        productionPickReturnMainService.saveMyWarehouseInOut(vInOutRecordMain);
        return HttpResult.ok();
    }

    /****************************** 委外领料单 **************************************/
    /**
     * 获取 委外领料单 单据编码
     */
    @ApiOperation("获取 委外领料单 单据编码")
    @GetMapping("getCodeForDelegate")
    public HttpResult getCodeForDelegate() {
        return HttpResult.ok(productionPickReturnMainService.getCodeForDelegate());
    }

    @ApiOperation("保存 委外领料单")
    @PostMapping("saveOrderForDelegate")
    public HttpResult saveOrderForDelegate(@RequestBody VProductionPickReturnMain productionPickReturnMain) {
        if(productionPickReturnMain.getBusinessType() == null) {
            throw new NuoNiuException("业务类型不能为空");
        }
        productionPickReturnMainService.saveOrderForDelegate(productionPickReturnMain);
        return HttpResult.ok();
    }
}
